﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace BusinessCommon.Utilities
{
    public class StringUtilities
    {
        public static string EncryptPassword(string pw)
        {
            string newPw = "";

            string[] salt = { "!", "@", "#", "$", "%", "^", "&", "*", "?", ">" };

            byte[] pwByteArr = System.Text.Encoding.UTF8.GetBytes(pw);

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            for (int i = 0; i < pw.Length; i = i + 2)
            {
                pw = pw.Insert(i, salt[i % 10].ToString());
            }

            pwByteArr = md5.ComputeHash(pwByteArr);

            foreach (var item in pwByteArr)
            {
                newPw += item.ToString("X2");
            }

            return newPw.ToLower();
        }

        public static bool IsNull(string stringCheck)
        {
            if (stringCheck == null || stringCheck.Equals("")) 
            {
                return true;
            }
            return false;
        }
    }
}
